package homework.level01model04.homework02;

import java.io.File;

public class Homework02 {

    //显示所有文件
   public static void showFiles(String name){
       File file = new File(name);
       if (!file.exists()){
           System.out.println("目录/文件不存在");
           return;
       }else{
           File[] files = file.listFiles();
           for (File file1 : files) {
               if (file1.isFile()){
                   System.out.println(file1);
               }else{
                   String absolutePath = file1.getAbsolutePath();
                   showFiles(absolutePath);
               }
           }
       }

   }

   //删除所有文件
   public static void deleteFiles(String name){
       File file = new File(name);
       if (!file.exists()){
           System.out.println("目录/文件不存在");
           return;
       }else{
           File[] files = file.listFiles(); //获取第一层文件集合
           for (File file1 : files) {
               if (file1.isFile()){
                   file1.delete();
               }else{
                   String absolutePath = file1.getAbsolutePath();
                   deleteFiles(absolutePath);
               }
           }
       }
       file.delete();
       System.out.println("删除成功");
   }
}


